﻿using FunArts.EasyDevOps.Shared.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunArts.EasyDevOps.Shared.Models.SshClient
{
    /// <summary>
    /// 连接信息
    /// </summary>
    public class SshClientConnectInfo
    {
        /// <summary>
        /// 服务器类型
        /// </summary>
        public SystemTypeEnum SystemType { get; set; }
        /// <summary>
        /// 系统版本
        /// </summary>
        public SystemVersionTypeEnum SystemVersionType { get; set; }
        /// <summary>
        /// 地址
        /// </summary>
        public string Host { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string User { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Pwd { get; set; }

        #region 创建执行命令
        /// <summary>
        /// 创建Linux执行命令
        /// </summary>
        /// <param name="linuxCommand"></param>
        /// <returns></returns>
        public string BuildCommand(ILinuxCommand linuxCommand)
        {
            return linuxCommand.BuildCommand(SystemVersionType);
        }

        public string BuildCommand(Func<ILinuxCommand> buildLinuxCommand)
        {
            ILinuxCommand linuxCommand = buildLinuxCommand();
            return BuildCommand(linuxCommand);
        }
        #endregion

    }

    public static class SshClientConnectInfoExtensions
    {
        public static bool CheckParam(this SshClientConnectInfo connectInfo,out string errMsg)
        {
            errMsg=string.Empty;
            if (connectInfo == null)
            {
                errMsg = "连接信息为空";
                return false;
            }

            if(string.IsNullOrWhiteSpace(connectInfo.Host))
            {
                errMsg = "Host为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(connectInfo.User))
            {
                errMsg = "User为空";
                return false;
            }

            if (string.IsNullOrWhiteSpace(connectInfo.Pwd))
            {
                errMsg = "Pwd为空";
                return false;
            }

            return true;
        }
    }
}
